package org.langqiao.algorithm;
/*
 * 基因牛问题
 */
import java.util.*;
public class GeneCow {
	
	private int age;
	
	public GeneCow afterYear(){
		age++;
		return age>2?new GeneCow():null;
	}
	
	//n表示n年后
	public static void showTotalCowNum(int n) {
		List<GeneCow> list = new ArrayList<GeneCow>();
		list.add(new GeneCow());
		for(int i = 0;i < n;i++) {
			int countNum = list.size();
			for(int j = 1;j < countNum;j++) {
				GeneCow cow = list.get(j).afterYear();
				if(cow != null) {
//					cow=list.get(j-1).afterYear()+list.get(j-2).afterYear();
				}
				list.add(cow);
			}
		}
		System.out.println(n+"年后共有："+list.size()+"头牛");
	}
	
	public static void main(String[] args) {
		showTotalCowNum(5);
	}
}
